// pages/infoYz/index.js
const qy = ['企业']
const gr = ['个体']
const staic = [
  {
    icon: '/images/home_icon_jh.png',
    title: '基本信息',
    status: '待完成',
    statusClass: 'status-pending',
    url: '/pages/jbxx/index',
    show: true,
    permission: ['all'],
    popBoxPageType: 'jbxx'
  },
  {
    icon: '/images/home_icon_jh.png',
    title: '营业执照',
    status: '待完成',
    statusClass: 'status-pending',
    url: '/pages/yzzz/index',
    show: true,
    permission: qy,
    popBoxPageType: 'yzzz'
  },
  // {
  //   icon: '/images/home_icon_jh.png',
  //   title: '特殊资质证件',
  //   status: '待完成',
  //   statusClass: 'status-pending',
  //   url: '/pages/yzzz/index',
  //   show: true,
  //   permission: qy,
  //   popBoxPageType: 'txzzzz'
  // },
  {
    icon: '/images/home_icon_jh.png',
    title: '身份证',
    status: '待完成',
    statusClass: 'status-pending',
    url: '/pages/sfz/index',
    show: true,
    permission: ['all'],
    popBoxPageType: 'sfz'
  },
  {
    icon: '/images/home_icon_jh.png',
    title: '办理人员信息',
    status: '待完成',
    statusClass: 'status-pending',
    url: '/pages/blryxx/index',
    show: true,
    permission: qy,
    popBoxPageType: 'blryxx'
  },
  {
    icon: '/images/home_icon_jh.png',
    title: '超级管理员',
    status: '待完成',
    statusClass: 'status-pending',
    show: true,
    permission: ['all'],
    popBoxPageType: 'cjglr'
  },
  {
    icon: '/images/home_icon_jh.png',
    title: '场地信息',
    status: '待完成',
    statusClass: 'status-pending',
    show: true,
    permission: qy,
    popBoxPageType: 'cdxx'
  },
  {
    icon: '/images/home_icon_jh.png',
    title: '收款账户信息',
    status: '待完成',
    statusClass: 'status-pending',
    url: '/pages/zhxx/index',
    show: true,
    permission: ['all'],
    popBoxPageType: 'zhxx'
  },
  {
    icon: '/images/home_icon_jh.png',
    title: '开票信息',
    status: '待完成',
    statusClass: 'status-pending',
    show: true,
    permission: ['all'],
    popBoxPageType: 'kpxx'
  }
]
Page({
  data: {
    isqy: true,
    infoItems: JSON.parse(JSON.stringify(staic)),
    array: [...qy, ...gr],
    arrayIndex: 0,
    showPopBox: false,
    popBoxPageType: '',
    pullDistance: 0, // 下拉距离
    pullStateText: '下拉刷新', // 下拉状态文本
    refresherEnabled: true, // 开启下拉刷新
    refresherTriggered: false, // 刷新状态
    contentList: [], // 内容列表
    page: 1, // 当前页码
    loadingMore: false, // 是否正在加载更多
    hasMoreData: true // 是否还有更多数据
  },
  closePopBox () {
    this.setData({showPopBox: false})
  },
  setinfoItems (e) {
      const popBoxPageType = e.detail.popBoxPageType
      const mb = this.data.infoItems
      const obj = mb.find(item => item.popBoxPageType === popBoxPageType)
      obj.statusClass = 'status-done'
      obj.status = '已完成'
      this.setData({infoItems: mb})
      if (e.detail.fn) {
        const obj = this.data.infoItems.find(item => item.statusClass === 'status-pending')
        if (obj) {
          this.setData({popBoxPageType: obj.popBoxPageType})
        }
      }
      if (mb.every(item => item.statusClass === 'status-done')) {
        wx.reLaunch({
          url: `/pages/business/index?activeTab=${this.data.isqy ? 'enterprise': 'individual'}`
        })
        return
      }
  },
  bindPickerChange (e) {
      this.setData({arrayIndex: e.detail.value})
      const nameType = this.data.array[e.detail.value]
      const filterarr = staic.filter(item => item.permission.indexOf(nameType) > -1 || item.permission.indexOf('all') > -1)
      if (qy.indexOf(nameType)) {
        this.setData({isqy: true})
      } else {
        this.setData({isqy: false})
      }
      this.setData({infoItems: filterarr})
  },
  gotoInfoYz () {
    wx.reLaunch({
      url: '/pages/register2/index?data=123'
    })
  },
  toinfopage (e) {
    this.setData({popBoxPageType: e.currentTarget.dataset.item.popBoxPageType})
    this.setData({showPopBox: true})
  },
  onShow () {
    const nameType = this.data.array[this.data.arrayIndex]
    console.log('nameType', nameType)
    const filterarr = staic.filter(item => item.permission.indexOf(nameType) > -1 || item.permission.indexOf('all') > -1)
    console.log('filterarr', filterarr)
      this.setData({infoItems: filterarr})
  }
});